package study.datastructure.leetcode.easy.day2;/**
 * @program: datastructure
 * @author: lcy
 * @create: 2024-09-15 16:29
 */

/**
 2024/9/15,
 */


public class BinarySearchSolution {
    public static int mySqrt(int x) {
        long low=0;
        long high=2147483647;

        while (low < high) {
            long mid=(low+high)>>>1;
            long midValue=mid*mid;
            if (midValue<x) {
                low=mid+1;
            }else if (x<midValue) {
                high=mid;
            }else{
                return (int)mid;
            }
        }
        return (int)low-1;
    }
    public static void main(String[] args) {
        System.out.println(mySqrt(1));
    }
}
